import java.util.ArrayList;
import java.util.Collections;

public class Inventory {
	ArrayList<Equip> helms;
	ArrayList<Equip> armors;
	ArrayList<Equip> weapons;
	ArrayList<Item> items;
	public Inventory(){
		helms = new ArrayList<Equip>();
		armors = new ArrayList<Equip>();
		weapons = new ArrayList<Equip>();
		items = new ArrayList<Item>();
	}
	public Inventory(	ArrayList<Equip> helms,
			ArrayList<Equip> armors,
			ArrayList<Equip> weapons,
			ArrayList<Item> items){
		this.helms = helms;
		this.armors = armors;
		this.weapons = weapons;
		this.items = items;
	}
	public void add(Object o){
		if(o instanceof Equip){
			Equip temp = (Equip) o;
			if(temp.getType() == Equip.Type.Armor){
				int index = Utilities.findIndex(temp.getName(), armors);
				if(index != -1)
					armors.get(index).setQty(armors.get(index).getQty() + temp.getQty());
				else{
					armors.add(new Equip(temp, 0));
					armors.get(Utilities.findIndex(temp.getName(), armors)).setQty(1);
					Collections.sort(armors);
				}
			}
			else if(temp.getType() == Equip.Type.Helm){
				int index = Utilities.findIndex(temp.getName(), helms);
				if(index != -1)
					helms.get(index).setQty(helms.get(index).getQty() + temp.getQty());
				else{
					helms.add(new Equip(temp, 0));
					helms.get(Utilities.findIndex(temp.getName(), helms)).setQty(1);
					Collections.sort(helms);
				}
			}
			else{
				int index = Utilities.findIndex(temp.getName(), weapons);
				if(index != -1)
					weapons.get(index).setQty(weapons.get(index).getQty() + temp.getQty());
				else{
					weapons.add(new Equip(temp, 0));
					weapons.get(Utilities.findIndex(temp.getName(), weapons)).setQty(1);
					Collections.sort(weapons);
				}
			}
		}
		else if(o instanceof Item){
			Item temp = (Item) o;
			int index = Utilities.findIndex(temp.getName(), items);
			if(index != -1)
				items.get(index).setQty(items.get(index).getQty() + temp.getQty());
			else{
				items.add(new Item(temp, 0));
				items.get(Utilities.findIndex(temp.getName(), items)).setQty(1);
				Collections.sort(items);
			}
		}
	}
}
